package com.sl.core.engine.log;

import cn.hutool.core.util.BooleanUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sl.core.engine.status.ProcessExecutorCompInfo;
import lombok.Getter;
import lombok.Setter;
import org.apache.hop.core.logging.ILogMessage;
import org.apache.hop.core.logging.ILoggingObject;
import org.apache.hop.core.logging.LogLevel;
import org.apache.hop.core.logging.LogMessage;

import java.util.List;

public class ProcessLogMessage extends LogMessage {

    @Getter
    @Setter
    private String threadName;


    @Getter
    @Setter
    private String threadId;

    @Getter
    @Setter
    private String tid;

    @Getter
    @Setter
    private String instanceId;

    @Getter
    @Setter
    private List<ProcessExecutorCompInfo> executorStepList;

    @Getter
    @Setter
    private Object stepInput;
    @Getter
    @Setter
    private Object stepOutput;


    @JsonIgnore
    @Getter
    private transient ILoggingObject logChannelHooks;


    public ProcessLogMessage(ILogMessage logMessage, ILoggingObject logChannelHooks) {
        super(logMessage.getMessage(), logMessage.getLogChannelId(), logMessage.getArguments(), logMessage.getLevel());
        this.logChannelHooks = logChannelHooks;
    }

    public ProcessLogMessage(String message, String logChannelId, LogLevel level) {
        super(message, logChannelId, level);
    }


    public ProcessLogMessage(List<ProcessExecutorCompInfo> logItem, String logChannelId, LogLevel level, ILoggingObject logChannelHooks) {
        super(null, logChannelId, level);
        this.executorStepList = logItem;
        this.logChannelHooks = logChannelHooks;
    }


    public ProcessLogMessage(Boolean inputOrOutputFlag, Object input, String logChannelId, LogLevel level, ILoggingObject logChannelHooks) {
        super(null, logChannelId, level);
        if (BooleanUtil.isTrue(inputOrOutputFlag)) {
            this.stepInput = input;
        } else {
            this.stepOutput = input;
        }
        this.logChannelHooks = logChannelHooks;
    }

    public ProcessLogMessage(String message, String logChannelId, LogLevel level, ILoggingObject logChannelHooks) {
        super(message, logChannelId, level);
        this.logChannelHooks = logChannelHooks;
    }

}
